<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="jbName">
        <el-input
          v-model="queryParams.jbName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="jbGender">
        <el-select v-model="queryParams.jbGender" placeholder="请选择性别" clearable>
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="政治面貌" prop="juPoliticalStatus">
        <el-select v-model="queryParams.juPoliticalStatus" placeholder="请选择政治面貌" clearable>
          <el-option
            v-for="dict in dict.type.party_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="年级" prop="jbGrade">
        <el-input
          v-model="queryParams.jbGrade"
          placeholder="请输入年级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业" prop="jbMajor">
        <el-input
          v-model="queryParams.jbMajor"
          placeholder="请输入专业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班级" prop="jobClass">
        <el-input
          v-model="queryParams.jobClass"
          placeholder="请输入班级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="培养方式" prop="juTrainingMethod">
        <el-input
          v-model="queryParams.juTrainingMethod"
          placeholder="请输入培养方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业去向" prop="graduationDestination">
        <el-input
          v-model="queryParams.graduationDestination"
          placeholder="请输入毕业去向"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="就业类别" prop="employmentCategory">
        <el-input
          v-model="queryParams.employmentCategory"
          placeholder="请输入就业类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入单位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位性质" prop="companyNature">
        <el-select v-model="queryParams.companyNature" placeholder="请选择单位性质" clearable>
          <el-option
            v-for="dict in dict.type.base_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="单位行业" prop="companyIndustry">
        <el-input
          v-model="queryParams.companyIndustry"
          placeholder="请输入单位行业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位所在地" prop="companyLocation">
        <el-input
          v-model="queryParams.companyLocation"
          placeholder="请输入单位所在地"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="负责辅导员" prop="juCounselor">
        <el-input
          v-model="queryParams.juCounselor"
          placeholder="请输入负责辅导员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['job_users:job_users:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['job_users:job_users:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['job_users:job_users:remove']"
        >删除</el-button>
      </el-col>
      <!-- 审核   -->
      <el-col :span="1.5">
        <el-button
          type="info"
          icon="el-icon-check"
          size="mini"
          @click="openAuditDialog"
          :disabled="multiple"
          v-hasPermi="['system:check']"
          plain
        >审核</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['job_users:job_users:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 确保visible是通过sync双向绑定 -->
    <audit-dialog
      :visible.sync="auditDialogVisible"
      table_name="xg_job_users"
      id_name="job_user_id"
      ref="audit"
      @submit="handleAuditSubmit"
    />

    <el-table v-loading="loading" :data="job_usersList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="充当主键" align="center" prop="jobUserId" />
      <el-table-column label="学号" align="center" prop="juStudentId" />
      <el-table-column label="姓名" align="center" prop="jbName" />
      <el-table-column label="性别" align="center" prop="jbGender">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.jbGender"/>
        </template>
      </el-table-column>
      <el-table-column label="政治面貌" align="center" prop="juPoliticalStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.party_type" :value="scope.row.juPoliticalStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="年级" align="center" prop="jbGrade" />
      <el-table-column label="专业" align="center" prop="jbMajor" />
      <el-table-column label="班级" align="center" prop="jobClass" />
      <el-table-column label="培养方式" align="center" prop="juTrainingMethod">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.edu_type" :value="scope.row.juTrainingMethod"/>
        </template>
      </el-table-column>
      <el-table-column label="联系方式" align="center" prop="juContactInfo" />
      <el-table-column label="毕业去向" align="center" prop="graduationDestination" />
      <el-table-column label="就业类别" align="center" prop="employmentCategory">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.job_type" :value="scope.row.employmentCategory"/>
        </template>
      </el-table-column>
      <el-table-column label="单位名称" align="center" prop="companyName" />
      <el-table-column label="单位性质" align="center" prop="companyNature">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.base_type" :value="scope.row.companyNature"/>
        </template>
      </el-table-column>
      <el-table-column label="单位行业" align="center" prop="companyIndustry" />
      <el-table-column label="单位所在地" align="center" prop="companyLocation" />
      <el-table-column label="单位联系人" align="center" prop="companyContactPerson" />
      <el-table-column label="负责辅导员" align="center" prop="juCounselor" />
      <el-table-column label="审核状态" align="center" prop="auditStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.audit_status" :value="scope.row.auditStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="未通过原因" align="center" prop="rejectionReason" />
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['job_users:job_users:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['job_users:job_users:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改就业信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1040x" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px" :inline="true">
        <el-form-item label="学号" prop="juStudentId">
          <el-input v-model="form.juStudentId" placeholder="请输入学号" />
        </el-form-item>
        <el-form-item label="姓名" prop="jbName">
          <el-input v-model="form.jbName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="jbGender">
          <el-select v-model="form.jbGender" placeholder="请选择性别">
            <el-option
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="政治面貌" prop="juPoliticalStatus">
          <el-select v-model="form.juPoliticalStatus" placeholder="请选择政治面貌">
            <el-option
              v-for="dict in dict.type.party_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年级" prop="jbGrade">
          <el-date-picker clearable
                          v-model="form.jbGrade"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请输入年级">
          </el-date-picker>

        </el-form-item>
        <el-form-item label="专业" prop="jbMajor">
          <el-input v-model="form.jbMajor" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="班级" prop="jobClass">
          <el-input v-model="form.jobClass" placeholder="请输入班级" />
        </el-form-item>
        <el-form-item label="培养方式" prop="juTrainingMethod">
          <el-input v-model="form.juTrainingMethod" placeholder="请输入培养方式" />
        </el-form-item>
        <el-form-item label="联系方式" prop="juContactInfo">
          <el-input v-model="form.juContactInfo" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="毕业去向" prop="graduationDestination">
          <el-input v-model="form.graduationDestination" placeholder="请输入毕业去向" />
        </el-form-item>
        <el-form-item label="就业类别" prop="employmentCategory">
          <el-input v-model="form.employmentCategory" placeholder="请输入就业类别" />
        </el-form-item>
        <el-form-item label="单位名称" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入单位名称" />
        </el-form-item>
        <el-form-item label="单位性质" prop="companyNature">
          <el-select v-model="form.companyNature" placeholder="请选择单位性质">
            <el-option
              v-for="dict in dict.type.base_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="单位行业" prop="companyIndustry">
          <el-input v-model="form.companyIndustry" placeholder="请输入单位行业" />
        </el-form-item>
        <el-form-item label="单位所在地" prop="companyLocation">
          <el-input v-model="form.companyLocation" placeholder="请输入单位所在地" />
        </el-form-item>
        <el-form-item label="单位联系人" prop="companyContactPerson">
          <el-input v-model="form.companyContactPerson" placeholder="请输入单位联系人" />
        </el-form-item>
        <el-form-item label="负责辅导员" prop="juCounselor">
          <el-input v-model="form.juCounselor" placeholder="请输入负责辅导员" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listJob_users, getJob_users, delJob_users, addJob_users, updateJob_users } from "@/api/job_users/job_users";
import AuditDialog from '@/components/AuditDialog/AuditDialog.vue'; // 引入审核子组件

export default {
  name: "Job_users",
  dicts: ['party_type', 'base_type', 'sys_user_sex', 'audit_status'],
  components: { AuditDialog },
  data() {
    return {
      // 控制审核对话框的显示
      auditDialogVisible: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 就业信息表格数据
      job_usersList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        jbName: null,
        jbGender: null,
        juPoliticalStatus: null,
        jbGrade: null,
        jbMajor: null,
        jobClass: null,
        juTrainingMethod: null,
        graduationDestination: null,
        employmentCategory: null,
        companyName: null,
        companyNature: null,
        companyIndustry: null,
        companyLocation: null,
        juCounselor: null,
        auditStatus: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        juStudentId: [
          { required: true, message: "学号不能为空", trigger: "blur" }
        ],
        jbName: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        jbGender: [
          { required: true, message: "性别不能为空", trigger: "change" }
        ],
        jbGrade: [
          { required: true, message: "年级不能为空", trigger: "blur" }
        ],
        jbMajor: [
          { required: true, message: "专业不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 打开审核对话框
    openAuditDialog() {
      if(this.ids!=null)
      {
        this.auditDialogVisible = true; // 显示审核对话框
        this.$refs['audit'].setData(this.ids);
      }
      else
        this.$message.error("请选择要审核的信息");
    },
    // 提交审核数据
    async handleAuditSubmit() {
      this.auditDialogVisible = false; // 关闭审核对话框
      await this.getList(); // 刷新数据列表
    },
    /** 查询就业信息列表 */
    getList() {
      this.loading = true;
      listJob_users(this.queryParams).then(response => {
        this.job_usersList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        jobUserId: null,
        juStudentId: null,
        jbName: null,
        jbGender: null,
        juPoliticalStatus: null,
        jbGrade: null,
        jbMajor: null,
        jobClass: null,
        juTrainingMethod: null,
        juContactInfo: null,
        graduationDestination: null,
        employmentCategory: null,
        companyName: null,
        companyNature: null,
        companyIndustry: null,
        companyLocation: null,
        companyContactPerson: null,
        juCounselor: null,
        userId: null,
        deptId: null,
        auditStatus: null,
        rejectionReason: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.jobUserId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加就业信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const jobUserId = row.jobUserId || this.ids
      getJob_users(jobUserId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改就业信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.jobUserId != null) {
            updateJob_users(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addJob_users(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const jobUserIds = row.jobUserId || this.ids;
      this.$modal.confirm('是否确认删除就业信息编号为"' + jobUserIds + '"的数据项？').then(function() {
        return delJob_users(jobUserIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('job_users/job_users/export', {
        ...this.queryParams
      }, `job_users_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
